angular.module('heGroup', [])

    .config(function GroupRoutes($stateProvider) {
        $stateProvider

            .state('groupList', {//路由名称
                parent: 'admin',
                url: '/groupList?{groupName:string}',//url以及参数定义
                params: {
                    page: { value: 1, squash: true },//初始化url中的参数，不需要可以不写
                    size: { value: 10, squash: true }
                },
                views: {
                    'main@admin': {
                        templateUrl: 'admin/group/list.html',//html地址
                        controller: 'HeGroupController as vm',//控制器和他的别名
                        resolve: {
                            initialList: function(HeGroup, $stateParams) {//从后台预加载的数据,Demo-注入的service
                                return HeGroup.search({
                                    groupName: $stateParams.groupName,
                                    pageInfo: {
                                        pageSize: $stateParams.size,
                                        pageNumber: $stateParams.page
                                    }
                                })
                            }
                        }
                    }
                }
            })
            .state('createGroup',{
                url: '/createGroup?{groupId:string}',
                params: {
                    groupId: null
                },
                controller: 'HeGroupAddController as vm',//控制器和他的别名
                templateUrl: 'admin/group/addGroup.html',
                resolve: {
                    params: function($stateParams){
                        return $stateParams.groupId;
                    },
                    validAdmin: function ($state,store) {
                        if(_.isNull(store.get('currentAdmin'))){
                            $state.go('session.signin')
                        }
                    }
                }
            })

    })

    .service('HeGroup', HeGroupModel)

    .controller('HeGroupController', HeGroupController)
    .controller('HeGroupAddController',HeGroupAddController)
    //弹出框组件
    .controller('delGroupComfimCtrl', function ($scope, $uibModalInstance) {

        $scope.ok = function () {
            $uibModalInstance.close('ok');
        };
        $scope.cancel = function () {
            $uibModalInstance.close('cancel');
        };
    })

    //弹出框组件
    .controller('createNewGroupCtrl', function ($scope, $uibModalInstance) {
        $scope.ok = function () {
            $uibModalInstance.close('ok');
        };
        $scope.cancel = function () {
            $uibModalInstance.close('cancel');
        };
    })

    //弹出框组件
    .controller('groupTipsCtrl', function ($scope, $uibModalInstance) {
        $scope.resultMsg = $scope.data.msg;
        $scope.ok = function () {
            $uibModalInstance.close('ok');
        };
    })
